package com.cqc.nestedrecyclerview01;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

/**
 * Created by ${cqc} on 2017/6/5.
 */

public class MyAdapter extends RecyclerView.Adapter {

    private List<ClassBean> classList;

    public MyAdapter(List<ClassBean> classList) {
        this.classList = classList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_1, parent, false);
        MyViewHolder holder = new MyViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
        MyViewHolder holder = (MyViewHolder) viewHolder;
        ClassBean info = classList.get(position);
        holder.tv1.setText(info.getClassName());

        holder.recyclerView2.setLayoutManager(new LinearLayoutManager(holder.recyclerView2.getContext()));
        MyAdapter2 adapter2 = new MyAdapter2(info.getStudents());
        holder.recyclerView2.setAdapter(adapter2);
    }

    @Override
    public int getItemCount() {
        return classList.size();
    }


    static class MyViewHolder extends RecyclerView.ViewHolder {

        TextView tv1;
        RecyclerView recyclerView2;

        public MyViewHolder(View itemView) {
            super(itemView);
            tv1 = (TextView) itemView.findViewById(R.id.tv1);
            recyclerView2 = (RecyclerView) itemView.findViewById(R.id.recyclerView2);
        }
    }
}
